home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_01_07 / 1n07056a < prev    next >
Text File  |  1990-11-03  |  3KB  |  107 lines

  1.  
  2.  
  3. /**************************************************
  4. * DXSEND.C -- Send a file to another network node.
  5. *
  6. *     Copyright 1990 Tom Jensen
  7. **************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include "netbios.h"
  13. #include "dxdef.h"
  14.  
  15. int IFLAG;
  16.  
  17. static void DispHelp(void);
  18.  
  19. int main(int argc, char **argv)
  20. {
  21.   struct NcbData  *ncb;
  22.   char          buffer [BUFSIZE];
  23.   char          lname[17], fname[17];
  24.   unsigned      retcode;
  25.   unsigned char   session;
  26.  
  27.   if(retcode = NetActive())
  28.     exit(retcode);
  29.  
  30.   if((ncb =
  31.     (struct NcbData *) malloc(sizeof(struct NcbData)))
  32.     == NULL)
  33.     exit(1);
  34.  
  35.   if(argc < 3)
  36.   {
  37.     DispHelp();
  38.     exit(1);
  39.   }
  40.  
  41.   /* process recipient's name */
  42.   NbExpandName(fname, argv[1]);
  43.   fname[15] = NAME_UNIQUE;    /* make the name unique */
  44.   fname[16] = '\0';           /* make it a C string */
  45.  
  46.   /* process local (sender's) name */
  47.   LocalName(buffer);          /* Get local net name */
  48.   NbExpandName(lname, buffer);
  49.   lname[15] = NAME_UNIQUE;    /* make the name unique */
  50.   lname[16] = '\0';           /* make it a C string */
  51.  
  52.   printf("Wait for unique name to be added.\n");
  53.   if((retcode = NbAddName(ncb, lname)) == NB_OK)
  54.     printf("Name \"%s\" added successfully.\n", lname);
  55.   else
  56.   {
  57.     printf("NETBIOS error %02xH encountered ", retcode);
  58.     printf(" encountered while adding \"%s\".\n", lname);
  59.     exit(1);
  60.   }
  61.  
  62.   if((retcode = NbOpenSession(ncb, lname, fname, &session))
  63.     == NB_OK)
  64.     printf("Session opened successfully.\n");
  65.   else
  66.   {
  67.     printf("NETBIOS error %02xH ", retcode);
  68.     printf("returned from Call command.\n");
  69.     NbDelName(ncb, lname);
  70.     exit(1);
  71.   }
  72.  
  73.   strcpy(buffer, DXPREFIX);
  74.   strcat(buffer, argv[2]);
  75.  
  76.   NbSendData(ncb, lname, fname, buffer, BUFSIZE, session);
  77.   NbReceiveData(ncb, lname, fname, buffer, BUFSIZE,
  78.     session);
  79.  
  80.   if(strncmp(buffer, OKMSG, OKSIZE) == 0)
  81.     printf("File successfully exchanged.\n");
  82.   else
  83.     printf("Probable error exchanging file.\n");
  84.  
  85.   NbCloseSession(ncb, lname, fname, session);
  86.   NbDelName(ncb, lname);
  87.  
  88.   return 0;
  89. }
  90.  
  91. /*******************************************
  92. * DispHelp -- Display a brief help message.
  93. *******************************************/
  94.  
  95. static void DispHelp(void)
  96. {
  97.   printf("Usage: DXSEND <receiving name> <file spec>\n");
  98.   printf("  Where <receiving name> is the network name ");
  99.   printf("of the recipient\n");
  100.   printf("  and <file spec> contains the data to be ");
  101.   printf("made available.\n");
  102.   printf("Note: The receiving name is case sensitive\n");
  103.   printf("  and the file spec must be known to the ");
  104.   printf("recipient.\n");
  105. }
  106.  
  107.